package com.example.winner.xmldesign;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.content.Intent;

public class MainActivity extends AppCompatActivity {
    RadioButton r1=null;
    RadioButton r2=null;
    RadioButton r3=null;
    RadioButton r4=null;
    RadioGroup rg=null;
    RadioButton current=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rg=(RadioGroup)findViewById(R.id.rg_answer);
        r1=(RadioButton)findViewById(R.id.a);
        r2=(RadioButton)findViewById(R.id.b);
        r3=(RadioButton)findViewById(R.id.c);
        r4=(RadioButton)findViewById(R.id.d);
        r1.setClickable(true);
        Button sure=(Button)findViewById(R.id.sure);
        Button cancel=(Button)findViewById(R.id.cancel);
        sure.setOnClickListener(new sure());
        cancel.setOnClickListener(new cancel());
    }
    public class sure implements OnClickListener
    {
        @Override
        public void onClick(View view)
        {
            String answer="";
            if(r1.isChecked())
            {
                answer="on";
            }
            else if(r2.isChecked())
            {
                answer="at";
            }
            else if(r3.isChecked())
            {
                answer="of";
            }
            else if(r4.isChecked())
            {
                answer="in";
            }
            Intent intent=new Intent();
            intent.setClass(MainActivity.this,Result.class);
            Bundle bundle=new Bundle();
            bundle.putString("answer",answer);
            intent.putExtras(bundle);
            startActivityForResult(intent,0);
        }
    }
    public class cancel implements OnClickListener
    {
        @Override
        public void onClick(View view)
        {
            rg.clearCheck();
            setTitle("");
        }
    }
    protected void onActivityResult(int request,int result,Intent data)
    {
        super.onActivityResult(request,result,data);
        if(request==0&&result==0)
        {
            Bundle bundle=data.getExtras();
            String answer=bundle.getString("answer");
        }
    }
}
